// pages/pickerhead/index.js
const api = require('../../config/api.js');
const apiDic = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  addPicker() {
    wx.navigateTo({
       url: '/pages/addPicker/index?userId='+this.data.userId
    });
  },

  getInvoiceTypes(){
    wx.request({
      url: apiDic.dictDataListUrl,
      data: {
        type: 'invoice_type'
      },
      method: 'GET',
      success: (res) => {
        if (res.data.code === 200) {
          let data = res.data.data
          if(data && data.length && this.data.invoiceTitle && this.data.invoiceTitle.invoiceType){
            let obj = data.find(x=>x.dictValue == this.data.invoiceTitle.invoiceType)
            if(obj){
              this.setData({
                'invoiceTitle.invoiceTypeName': obj.dictLabel
              })
            }
          }
          
        }
      }
    });
  },

  editPicker(){
    let invoiceTitle = JSON.stringify(this.data.invoiceTitle)
    wx.navigateTo({
      url: '/pages/addPicker/index?userId='+this.data.userId+'&invoiceTitle='+invoiceTitle
   });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let invoiceTitle = options.invoiceTitle;
    let userId = options.userId;
    this.setData({
      invoiceTitle:JSON.parse(invoiceTitle || null),
      userId:userId
    })
    this.getInvoiceTypes()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})